
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;


    
public class Ficheiro implements Serializable{

    private String filename;
    private byte[] buffer;

    

    public Ficheiro(String filename,byte[] buffer){
       this.filename=filename;
        this.buffer=buffer;
    }
    public Ficheiro(Ficheiro f){
        filename=f.getName();
        buffer=f.getBuffer();
    }

    public Ficheiro(){
        filename="";
        buffer="".getBytes();
    }

    public String getName() {return filename;}
    public byte[] getBuffer() {return buffer;}


    public void setName(String filename) {this.filename = filename;}
    public void setBuffer(byte[] buffer) {this.buffer = buffer;}


    public static Ficheiro bytesToFicheiro (byte[] bytes){
      Object obj = null;
      
      try {
        ByteArrayInputStream bis = new ByteArrayInputStream (bytes);
        ObjectInputStream ois = new ObjectInputStream (bis);
        obj = ois.readObject();
      }
      catch (IOException ex) {
      }
      catch (ClassNotFoundException ex) {
      }
     
      return (Ficheiro) obj;
    }  
    
}
    
